package android.slc.box.core.launcher;

import android.slc.box.core.scope.StageScope;
import android.slc.box.core.virtual_android.Bundle;
import cn.hutool.core.util.ArrayUtil;
import de.saxsys.mvvmfx.FxmlView;
import de.saxsys.mvvmfx.Scope;
import de.saxsys.mvvmfx.ViewModel;
import javafx.stage.Stage;

public interface StageLauncher extends WindowLauncher<Stage> {

    @Override
    default <ViewType extends FxmlView<? extends ViewModelType>, ViewModelType extends ViewModel> void launcherWindow(Stage targetWindow, Class<ViewType> viewClass, Bundle bundle, Scope... scopes) {
        launcherWindow(targetWindow, viewClass, new StageLauncherConfigImpl(), bundle, scopes);
    }

    /**
     * 启动窗口
     *
     * @param targetWindow
     * @param viewClass
     * @param scopes
     * @param <ViewType>
     * @param <ViewModelType>
     */
    default <ViewType extends FxmlView<? extends ViewModelType>, ViewModelType extends ViewModel> void launcherWindow(Stage targetWindow,
                                                                                                                      Class<ViewType> viewClass,
                                                                                                                      StageLauncherConfig stageLauncherConfig,
                                                                                                                      Scope... scopes) {
        this.launcherWindow(targetWindow, viewClass, stageLauncherConfig, null, scopes);
    }

    /**
     * 启动窗口
     *
     * @param targetWindow
     * @param viewClass
     * @param bundle
     * @param scopes
     * @param <ViewType>
     * @param <ViewModelType>
     */
    default <ViewType extends FxmlView<? extends ViewModelType>, ViewModelType extends ViewModel> void launcherWindow(Stage targetWindow,
                                                                                                                      Class<ViewType> viewClass,
                                                                                                                      StageLauncherConfig stageLauncherConfig,
                                                                                                                      Bundle bundle,
                                                                                                                      Scope... scopes) {
        StageScope stageScope = StageScope.newInstance(getWindow(), targetWindow, stageLauncherConfig);
        Scope[] scopeArray = ArrayUtil.append(scopes, stageScope);
        launcherWindow(targetWindow, createView(viewClass, bundle, scopeArray));
    }


}
